//
//  CCNavigationController.m
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/8/30.
//  Copyright © 2020 lidianchao. All rights reserved.
//

#import "CCNavigationController.h"

@interface CCNavigationController ()

@end

@implementation CCNavigationController

/**
 *  第一次使用这个类的时候会调用(一次)
 */
+(void)initialize
{
    // 设置导航条样式
    //获取所有导航条
    UINavigationBar *navBar = [UINavigationBar appearance];
    //横竖屏都显示
//    [navBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
    //标题颜色
    if (@available(iOS 10.0, *)) {
        [[UITabBar appearance] setUnselectedItemTintColor:[self hexStringToColor:@"333333"]];
    } else {
        // Fallback on earlier versions
    }
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    //设置导航栏Item白色
    [[UINavigationBar appearance]setTintColor:[self hexStringToColor:@"e74c3c"]];
    //设置背景色
    [navBar setBarTintColor:[UIColor whiteColor]];
    
    //navigationBar不透明
//    [navBar setTranslucent:NO];

}

//规避iPhone X上push的时候tabbar上移的问题
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
    // 修改tabBra的frame
    CGRect frame = self.tabBarController.tabBar.frame;
    frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
    self.tabBarController.tabBar.frame = frame;
}

+ (UIColor*)hexStringToColor:(NSString *)stringToConvert
{
    NSString *cString=[[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]uppercaseString];
    if ([cString length]<6)return [UIColor blackColor];
    if ([cString hasPrefix:@"0X"])cString=[cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"]) cString=[cString substringFromIndex:1];
    if ([cString length]!=6)return [UIColor blackColor];
    NSRange range;
    range.location=0;
    range.length=2;
    NSString *rString=[cString substringWithRange:range];range.location=2;
    NSString *gString=[cString substringWithRange:range];
    range.location=4;
    NSString *bString=[cString substringWithRange:range];
    unsigned int r,g,b;
    [[NSScanner scannerWithString:rString]scanHexInt:&r];
    [[NSScanner scannerWithString:gString]scanHexInt:&g];
    [[NSScanner scannerWithString:bString]scanHexInt:&b];
    return [UIColor colorWithRed:((float)r/255.0f) green:((float)g/255.0) blue:((float)b/255.0f) alpha:1];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
